package com.example.wuqujingdianphone.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.example.wuqujingdianphone.R;
import com.example.wuqujingdianphone.adapter.AudioListAdapter;
import com.example.wuqujingdianphone.adapter.VideoListAdapter;
import com.example.wuqujingdianphone.api.ApiConfig;
import com.example.wuqujingdianphone.base.BaseActivity;
import com.example.wuqujingdianphone.bean.AudioListBean;
import com.example.wuqujingdianphone.bean.TingshuHomeBean;
import com.example.wuqujingdianphone.bean.VideoListBean;
import com.example.wuqujingdianphone.utils.GsonUtil;
import com.example.wuqujingdianphone.utils.NiceDialogUtils;
import com.example.wuqujingdianphone.utils.SPUtil;
import com.example.wuqujingdianphone.utils.ToastUtil;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 音频列表
 */
public class AudioListActivity extends BaseActivity {
    private String title = "";
    private String bac = "";

    @BindView(R.id.toolbar)
    Toolbar mToolbar;
    @BindView(R.id.title)
    TextView mTitle;
    @BindView(R.id.recyclerView)
    RecyclerView mRecyclerView;

    private AudioListAdapter mAdapter;
    private ArrayList<TingshuHomeBean.ChildsBean.ListBean.ModelBean> listTwo = new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_audio_list);
        ButterKnife.bind(this);
        listTwo = getIntent().getExtras().getParcelableArrayList("listFrom");
        title = getIntent().getStringExtra("title");
        bac = getIntent().getStringExtra("bac");
        mTitle.setText(title);
        mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        initView();
    }

    private void initView() {
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mRecyclerView.addItemDecoration(new DividerItemDecoration(this, LinearLayout.VERTICAL));
        mAdapter = new AudioListAdapter(getApplicationContext(), null);
        mAdapter.openLoadAnimation();
        mRecyclerView.setAdapter(mAdapter);
        mAdapter.setNewData(listTwo);
        mAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                boolean isLogin = SPUtil.getBoolean(AudioListActivity.this, "isLogin", false);

                if (isLogin) {
                    Intent intent = new Intent(getApplicationContext(), AudioPlayToActivity.class);
                    intent.putExtra("playUrl", ApiConfig.APP_URL + listTwo.get(position).getUrl());
                    intent.putExtra("title", listTwo.get(position).getTitle());
                    intent.putExtra("bac", bac);
                    startActivity(intent);
                } else {
                    ToastUtil.show("抱歉！您还没有登录哦！");
                }
            }
        });
    }
}
